package cst.a331cs.startproject331;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import cst.a331cs.startproject331.bean.Weatherinfo;
import cst.a331cs.startproject331.listener.Weatherlistener;
import cst.a331cs.startproject331.model.Weathermodel;

public class MainActivity extends AppCompatActivity {
    private EditText city_edit;
    private Button btn_1;
    private TextView city_text;
    private TextView temp_text;
    private TextView wd_text;
    private TextView ws_text;
    private Weathermodel model;
    private Weatherlistener listener;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        city_edit = (EditText) findViewById(R.id.city_edit);
        btn_1 = (Button) findViewById(R.id.btn_1);
        city_text =(TextView) findViewById(R.id.city_text);
        temp_text = (TextView) findViewById(R.id.temp_text);
        wd_text =(TextView) findViewById(R.id.wd_text);
        ws_text =(TextView) findViewById(R.id.ws_text);
        listener = new Weatherlistener() {
            @Override
            public void onResponse(Weatherinfo w) {
                city_text.setText(w.getCity());
                temp_text.setText(w.getTemp());
            }

            @Override
            public void onFail(String msg) {
                city_text.setText("解析错误");
            }
        };
        btn_1.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                model = new Weathermodel();
                model.getWeather(city_edit.getText().toString(),
                       listener);
            }

        });

    }
}
